#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char s[500500];
char c[500500];
int nt[500500];
int len;
void getnt()
{
	int i = 0;
	int t = -1;
	nt[0] = -1;
	while(i<len)
	{
		if(t==-1||c[t]==c[i])
		{
			i++;
			t++;
			nt[i]= t;
		}
		else t  = nt[t];
	}
}
int main()
{
	while(scanf("%s %s",s,c)!=EOF)
	{
		len = strlen(c);
		//printf("%d\n",len);
		int l = strlen(s);
		getnt();
		int s0,s1;
		s0 = s1 = 0;
		for(int i = 0;i<l;i++)
		{
			if(s[i]=='0')s0++;
			else s1++;
		}	
		int j = 0;
		int i = 0;	
		while(s1>0&&s0>0)
		{
			if(c[j]=='0') s0--;
			else s1--;
			printf("%c",c[j]);
		//	printf("j = %d\n",j);
		//	printf("s1 = %d s0 = %d\n",s1,s0);
			j++;
			if(j==len)
			{
				j = nt[len];
			//	printf("\n***%d\n",j);
			}
		}
		while(s0>0) 
		{
			printf("0");
			s0--;
		}
		while(s1>0)
		{
			printf("1");
			s1--;
		} 
		printf("\n");
	}
}
